package repl

import (
	"fmt"
	"os"
	"parse/src/interpreter"
	"parse/src/lexer"
	"parse/src/parser"
)

//${PATHSS}/LLVM-C.lib
//${PATHSS}/LLVMAggressiveInstCombine.lib
//${PATHSS}/LLVMAnalysis.lib
//${PATHSS}/LLVMAsmParser.lib
//${PATHSS}/LLVMAsmPrinter.lib
//${PATHSS}/LLVMBinaryFormat.lib
//${PATHSS}/LLVMBitReader.lib
//${PATHSS}/LLVMBitstreamReader.lib
//${PATHSS}/LLVMBitWriter.lib
//${PATHSS}/LLVMCFGuard.lib
//${PATHSS}/LLVMCFIVerify.lib
//${PATHSS}/LLVMCodeGen.lib
//${PATHSS}/LLVMCodeGenTypes.lib
//${PATHSS}/LLVMCoroutines.lib
//${PATHSS}/LLVMCoverage.lib
//${PATHSS}/LLVMDebugInfoBTF.lib
//${PATHSS}/LLVMDebugInfoCodeView.lib
//${PATHSS}/LLVMDebuginfod.lib
//${PATHSS}/LLVMDebugInfoDWARF.lib
//${PATHSS}/LLVMDebugInfoGSYM.lib
//${PATHSS}/LLVMDebugInfoLogicalView.lib
//${PATHSS}/LLVMDebugInfoMSF.lib
//${PATHSS}/LLVMDebugInfoPDB.lib
//${PATHSS}/LLVMDemangle.lib
//${PATHSS}/LLVMDiff.lib
//${PATHSS}/LLVMDlltoolDriver.lib
//${PATHSS}/LLVMDWARFLinker.lib
//${PATHSS}/LLVMDWARFLinkerClassic.lib
//${PATHSS}/LLVMDWARFLinkerParallel.lib
//${PATHSS}/LLVMDWP.lib
//${PATHSS}/LLVMExecutionEngine.lib
//${PATHSS}/LLVMExegesis.lib
//${PATHSS}/LLVMExegesisX86.lib
//${PATHSS}/LLVMExtensions.lib
//${PATHSS}/LLVMFileCheck.lib
//${PATHSS}/LLVMFrontendDriver.lib
//${PATHSS}/LLVMFrontendHLSL.lib
//${PATHSS}/LLVMFrontendOffloading.lib
//${PATHSS}/LLVMFrontendOpenACC.lib
//${PATHSS}/LLVMFrontendOpenMP.lib
//${PATHSS}/LLVMFuzzerCLI.lib
//${PATHSS}/LLVMFuzzMutate.lib
//${PATHSS}/LLVMGlobalISel.lib
//${PATHSS}/LLVMHipStdPar.lib
//${PATHSS}/LLVMInstCombine.lib
//${PATHSS}/LLVMInstrumentation.lib
//${PATHSS}/LLVMInterfaceStub.lib
//${PATHSS}/LLVMInterpreter.lib
//${PATHSS}/LLVMipo.lib
//${PATHSS}/LLVMIRPrinter.lib
//${PATHSS}/LLVMIRReader.lib
//${PATHSS}/LLVMJITLink.lib
//${PATHSS}/LLVMLibDriver.lib
//${PATHSS}/LLVMLineEditor.lib
//${PATHSS}/LLVMLinker.lib
//${PATHSS}/LLVMLTO.lib
//${PATHSS}/LLVMMC.lib
//${PATHSS}/LLVMMCA.lib
//${PATHSS}/LLVMMCDisassembler.lib
//${PATHSS}/LLVMMCJIT.lib
//${PATHSS}/LLVMMCParser.lib
//${PATHSS}/LLVMMIRParser.lib
//${PATHSS}/LLVMObjCARCOpts.lib
//${PATHSS}/LLVMObjCopy.lib
//${PATHSS}/LLVMObject.lib
//${PATHSS}/LLVMObjectYAML.lib
//${PATHSS}/LLVMOption.lib
//${PATHSS}/LLVMOrcDebugging.lib
//${PATHSS}/LLVMOrcJIT.lib
//${PATHSS}/LLVMOrcShared.lib
//${PATHSS}/LLVMOrcTargetProcess.lib
//${PATHSS}/LLVMPasses.lib
//${PATHSS}/LLVMProfileData.lib
//${PATHSS}/LLVMRemarks.lib
//${PATHSS}/LLVMRuntimeDyld.lib
//${PATHSS}/LLVMScalarOpts.lib
//${PATHSS}/LLVMSelectionDAG.lib
//${PATHSS}/LLVMSymbolize.lib
//${PATHSS}/LLVMTableGen.lib
//${PATHSS}/LLVMTableGenCommon.lib
//${PATHSS}/LLVMTableGenGlobalISel.lib
//${PATHSS}/LLVMTarget.lib
//${PATHSS}/LLVMTargetParser.lib
//${PATHSS}/LLVMTextAPI.lib
//${PATHSS}/LLVMTextAPIBinaryReader.lib
//${PATHSS}/LLVMTransformUtils.lib
//${PATHSS}/LLVMVectorize.lib
//${PATHSS}/LLVMWindowsDriver.lib
//${PATHSS}/LLVMWindowsManifest.lib
//${PATHSS}/LLVMX86AsmParser.lib
//${PATHSS}/LLVMXRay.lib
//${PATHSS}/LTO.lib
//${PATHSS}/lzma.lib
//${PATHSS}/Remarks.lib
//${PATHSS}/zlibd.lib
//${PATHSS}/zstd.lib
/*
*
开始程序
out 输出的
color 颜色
*/
func Start(input string, contextObj *interpreter.Context, interpreterObj *interpreter.Interpreter) (*interpreter.RTResult, *interpreter.Error) {

	/** 产生 tokens **/
	lexerObj := lexer.New("控制台输入", input)
	tokens_, err := lexerObj.MakeTokens()
	if err != nil {
		return nil, err
	}
	/** 产生 ast 语法树 **/
	parserObj := parser.New(tokens_)
	ast := parserObj.Parse()
	if ast.Error_ != nil {
		return nil, ast.Error_
	}
	/** 运行程序 **/
	// 开始运行总节点，这里是运行所有节点的入口函数，（一个程序会被解析成为一个节点，
	// 这个节点里面会有很多的子节点，就是通过分析这个节点以及其子节点实现运行程序的）
	result := interpreterObj.Visit(ast.Node, contextObj)
	return result, nil
}

// 做一些程序的初始化
func Init() {
	// 得到当前的文件夹的根路径
	wd, err := os.Getwd()
	if err != nil {
		// 有错误就退出
		fmt.Println(err.Error())
		os.Exit(1)
	}
	fmt.Println(wd)
}
